package com.ruoyi.rest.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.rest.domain.SillRest;
import com.ruoyi.rest.service.ISillRestService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工请假表Controller
 * 
 * @author ruoyi
 * @date 2024-08-10
 */
@RestController
@RequestMapping("/rest/rest")
public class SillRestController extends BaseController
{
    @Autowired
    private ISillRestService sillRestService;

    /**
     * 查询员工请假表列表
     */
    @PreAuthorize("@ss.hasPermi('rest:rest:list')")
    @GetMapping("/list")
    public TableDataInfo list(SillRest sillRest)
    {
        startPage();
        List<SillRest> list = sillRestService.selectSillRestList(sillRest);
        return getDataTable(list);
    }

    /**
     * 导出员工请假表列表
     */
    @PreAuthorize("@ss.hasPermi('rest:rest:export')")
    @Log(title = "员工请假表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SillRest sillRest)
    {
        List<SillRest> list = sillRestService.selectSillRestList(sillRest);
        ExcelUtil<SillRest> util = new ExcelUtil<SillRest>(SillRest.class);
        util.exportExcel(response, list, "员工请假表数据");
    }
    /**
     * 获取所有的工号
     * */

    @GetMapping("/tree")
    public AjaxResult getTree()
    {
        return success(sillRestService.getXqTree());
    }

    /**
     * 获取工号多少
     */
    @GetMapping("/treeName/{restNum}")
    public AjaxResult getNameTree(@PathVariable("restNum") String restNum)
    {

        return success(sillRestService.getNameTree(restNum));
    }

    /**
     * 获取员工请假表详细信息
     */
    @PreAuthorize("@ss.hasPermi('rest:rest:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sillRestService.selectSillRestById(id));
    }

    /**
     * 新增员工请假表
     */
    @PreAuthorize("@ss.hasPermi('rest:rest:add')")
    @Log(title = "员工请假表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SillRest sillRest)
    {
        return toAjax(sillRestService.insertSillRest(sillRest));
    }

    /**
     * 修改员工请假表
     */
    @PreAuthorize("@ss.hasPermi('rest:rest:edit')")
    @Log(title = "员工请假表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SillRest sillRest)
    {
        return toAjax(sillRestService.updateSillRest(sillRest));
    }

    /**
     * 删除员工请假表
     */
    @PreAuthorize("@ss.hasPermi('rest:rest:remove')")
    @Log(title = "员工请假表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sillRestService.deleteSillRestByIds(ids));
    }
}
